/* GUI CONVERTED from reptrp30.p (converter v1.76) Mon Sep 17 22:18:35 2001 */
/* reptrp30.p - INVENTORY VALUATION REPORT WITH WORK IN PROCESS               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.10.1.6 $                                                     */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 1.0      LAST MODIFIED: 01/09/87   BY: EMB *A9*                  */
/* REVISION: 1.0      LAST MODIFIED: 03/18/87   BY: EMB                       */
/* REVISION: 4.0      LAST MODIFIED: 02/17/88   BY: RL  *A171*                */
/* REVISION: 4.0      LAST MODIFIED: 02/24/88   BY: WUG *A175*                */
/* REVISION: 5.0      LAST MODIFIED: 10/10/90   BY: emb *B798*                */
/* REVISION: 6.0      LAST MODIFIED: 05/21/90   BY: WUG *D002*                */
/* REVISION: 6.0      LAST MODIFIED: 12/03/90   BY: emb *D239*                */
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*                */
/* REVISION: 7.3      LAST MODIFIED: 06/02/93   BY: dzs *GB32*                */
/* REVISION: 7.4      LAST MODIFIED: 01/12/94   BY: qzl *H276*                */
/* REVISION: 7.4      LAST MODIFIED: 08/04/94   BY: pxd *GL10*                */
/*                                   08/27/94   BY: bcm *GL62*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/95   BY: qzl *G19F*                */
/* REVISION: 7.4      LAST MODIFIED: 11/15/95   BY: jym *G1DB*                */
/* REVISION: 8.6      LAST MODIFIED: 10/15/97   BY: gyk *K10T*                */
/* REVISION: 8.6      LAST MODIFIED: 10/24/97   BY: *G2PZ*  Manmohan Pardesi  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.10.1.5  BY: Hualin Zhong DATE: 06/13/01 ECO: *N0ZF*            */
/* $Revision: 1.10.1.6 $  BY: Manjusha Inglay  DATE: 08/28/01 ECO: *P01R*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* DISPLAY TITLE */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reptrp30_p_1 "Use Routing Inventory Value for WIP"
/* MaxLen: Comment: */

&SCOPED-DEFINE reptrp30_p_4 "WIP Value"
/* MaxLen: Comment: */

&SCOPED-DEFINE reptrp30_p_6 "Piece Count"
/* MaxLen: Comment: */

&SCOPED-DEFINE reptrp30_p_9 "Cost per Opn"
/* MaxLen: Comment: */

&SCOPED-DEFINE reptrp30_p_10 "F/G Value"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable abc like pt_abc.
define variable abc1 like pt_abc.
define variable part like pt_part.
define variable part1 like pt_part.
define variable vend like pt_vend.
define variable vend1 like pt_vend.
define variable line like pt_prod_line.
define variable line1 like pt_prod_line.
define variable ptgroup like pt_group.
define variable group1 like pt_group.
define variable wip_cost like mfc_logical label {&reptrp30_p_1}.
define variable opcost2 like sct_cst_tot.
define variable ext_std like sct_cst_tot column-label {&reptrp30_p_10}.
define variable ext_wip as decimal column-label {&reptrp30_p_4}
   format "->>>>,>>>,>>9.99<<<".
define variable wip_value like sct_cst_tot.
define variable rjct_value like sct_cst_tot.
define variable acc like sct_cst_tot extent 2.
define variable std_wip like sct_cst_tot.
define variable unit_setup like sct_cst_tot.
define variable ro_rmks as character format "x(35)".
define variable last_value like std_wip.
define variable op as integer extent 100.
define variable wip like wr_qty_wip.
define variable rjct as decimal extent 100.
define variable subtract as decimal extent 2.
define variable i as integer.
define variable total_qty_oh like in_qty_oh column-label {&reptrp30_p_6}.
define variable site like si_site.
define variable site1 like si_site.
define variable sctcst like sct_cst_tot.
define variable opcost like sct_cst_tot column-label {&reptrp30_p_9}.
define variable op_date as date.
define variable glx_set like cs_set.
define variable glx_mthd like cs_method.
define variable cur_set like cs_set.
define variable cur_mthd like cs_method.
define variable opdate like op_date.
define variable worouting like wo_routing.
define variable woqtyord like wo_qty_ord.
define variable reject like wr_qty_rjct.
define variable wobom like wo_bom_code.
define variable l_report_total as character format "x(17)".
define variable l_site_total as character format "x(17)".
define variable l_item_total as character format "x(17)".
define variable l_product_line_total as character format "x(17)".
define variable l_cum_order_total as character format "x(17)".


/* SELECT FORM */

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
site    colon 15
   site1   label {t001.i} colon 49
   part    colon 15
   part1   label {t001.i} colon 49
   ptgroup colon 15
   group1  label {t001.i} colon 49
   line    colon 15
   line1   label {t001.i} colon 49
   vend    colon 15
   vend1   label {t001.i} colon 49
   abc     colon 15
   abc1    label {t001.i} colon 49 skip (1)
   space(1)
   wip_cost
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

assign
   l_report_total       = getTermLabel("REPORT_TOTAL",15) + ": "
   l_site_total         = getTermLabel("SITE_TOTAL",15) + ": "
   l_item_total         = getTermLabel("ITEM_TOTAL",15) + ": "
   l_product_line_total = getTermLabel("PRODUCT_LINE_TOTAL",15) + ": "
   l_cum_order_total    = getTermLabel("CUMULATIVE_ORDER_TOTAL",15) + ": ".

/* REPORT BLOCK */

{wbrp01.i}

/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:


   if part1 = hi_char then
      part1 = "".
   if group1 = hi_char then
      group1 = "".
   if line1 = hi_char then
      line1 = "".
   if vend1 = hi_char then
      vend1 = "".
   if site1 = hi_char then
      site1 = "".
   if abc1 = hi_char then
      abc1 = "".

   if c-application-mode <> 'web' then
   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update
             &fields = "   site site1 part part1 ptgroup
                       group1 line line1 vend vend1 abc abc1 wip_cost"
             &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data')) then do:

      bcdparm = "".
      {mfquoter.i site   }
      {mfquoter.i site1  }
      {mfquoter.i part   }
      {mfquoter.i part1  }
      {mfquoter.i ptgroup}
      {mfquoter.i group1 }
      {mfquoter.i line   }
      {mfquoter.i line1  }
      {mfquoter.i vend   }
      {mfquoter.i vend1  }
      {mfquoter.i abc    }
      {mfquoter.i abc1   }
      {mfquoter.i wip_cost}

      if part1 = "" then
         part1 = hi_char.
      if group1 = "" then
         group1 = hi_char.
      if line1 = "" then
         line1 = hi_char.
      if vend1 = "" then
         vend1 = hi_char.
      if site1 = "" then
         site1 = hi_char.
      if abc1 = "" then
         abc1 = hi_char.

   end.
   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:

define buffer sctdet for sct_det.


   {mfphead.i}

   /*******************************  GB32 ****************************************
   THE PROGRAM LOGIC HAS BEEN CHANGED IN ITS ENTIRETY.
   IF THE PROMPT FOR THE WIP COST IS NO THEN THE WIP COST IS TAKEN FROM
   THE iro_det FILE, ELSE IF THE PROMPT IS YES THEN THE PLUGGED COST IS TAKEN
   AS WIP COST FROM THE ro_det FILE.
   ******************************************************************************/

   FORM /*GUI*/ 
      in_site colon 10
      si_desc no-label at 39
      pt_prod_line colon 10
      pl_desc no-label at 39
   with STREAM-IO /*GUI*/  frame b down width 132 no-attr-space.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame b:handle).

   FORM /*GUI*/ 
      wo_nbr
      wo_lot
      wo_status
      wr_op
      worouting
      reject
      wr_qty_wip
      opcost
      ext_wip
   with STREAM-IO /*GUI*/  frame d down width 132 no-attr-space.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame d:handle).

   for each in_mstr no-lock
   where (in_site >= site and in_site <= site1)
     and (in_part >= part and in_part <= part1)
     and (in_abc >= abc and in_abc <= abc1),
   each pt_mstr no-lock
   where pt_part = in_part
     and (pt_group >= ptgroup and pt_group <= group1)
     and (pt_vend >= vend and pt_vend <= vend1)
     and (pt_prod_line >= line and pt_prod_line <= line1),
   each wo_mstr no-lock
   where wo_part = in_part and wo_type = "C"
     and wo_site = in_site,
   each wr_route no-lock
   where wr_lot = wo_lot
   break by in_site by pt_prod_line by wo_part by wo_lot
         by wr_op with frame d:

      if page-size - line-counter < 5 then
         page.

      if first-of(pt_prod_line) then do with frame b side-labels:
         page.
         find pl_mstr no-lock where pl_prod_line = pt_prod_line no-error.
         find si_mstr no-lock where si_site = in_site no-error.
         if available si_mstr then
            display in_site si_desc WITH STREAM-IO /*GUI*/ .
         if available pl_mstr then
            display pt_prod_line pl_desc WITH STREAM-IO /*GUI*/ .
         down 1.
      end.

      assign
         wip      = 0
         ext_wip  = 0
         opcost   = 0
         opdate   = today
         woqtyord = wo_qty_ord.

      if woqtyord = 0 then
         woqtyord = 1.

      worouting = wo_routing.

      if worouting = "" then
         worouting = wo_part.

      if wo_bom_code <> "" then
         wobom = wo_bom_code.
      else
         wobom = wo_part.

      /* DETERMINE COST SET glx_set */

      {gprun.i ""csavg01.p"" "(input  wo_part,
                               input  wo_site,
                               output glx_set,
                               output glx_mthd,
                               output cur_set,
                               output cur_mthd)"}

      /* IF PROMPT FOR WIP COST IS NO GET COST FROM iro_det */

      if not wip_cost then do:

         if not can-find (iro_det where iro_part = wobom
            and iro_site = wo_site
            and iro_cost_set = glx_set
            and iro_routing = worouting
            and iro_op = wr_op) then do transaction:
            /* Create iro_det */
            /* CHANGED INPUT PARAMETER FROM wo_part TO wobom */
            {gprun.i ""rwroru1a.p"" "(input wo_site,
                                      input glx_set,
                                      input worouting,
                                      input wobom,
                                      input woqtyord,
                                      input opdate,
                                      input yes)"}

         end.

         find iro_det
         where iro_part = wobom
           and iro_site = wo_site
           and iro_cost_set = glx_set
           and iro_routing = worouting
           and iro_op = wr_op no-lock no-error.

         if available iro_det then
            opcost = iro_cost_tot.

      end. /* if wip_cost = no */

      /* IF PROMPT FOR WIP COST IS YES GET PLUGGED COST FROM ro_det */

      if wip_cost then do:
         find ro_det no-lock
         where ro_routing = worouting
           and ro_op = wr_op
           and (ro_start = ? or ro_start <= today)
           and (ro_end = ? or ro_end >= today) no-error.

         if available ro_det then
            opcost = ro_inv_value.

      end. /* if wip_cost = yes */

      assign
         reject = max (wr_qty_rjct, 0)
         wip = max ((max(wr_qty_wip,0) + reject), 0).

      if opcost = ? then
         opcost = 0.

      find prev iro_det
      where iro_part = wobom
        and iro_site = wo_site
        and iro_cost_set = glx_set
        and iro_routing = worouting
        and iro_op < wr_op no-lock no-error.
      if available iro_det then
         opcost2 = iro_cost_tot.
      else
         opcost2 = 0.

      ext_wip = ( (wr_qty_wip - max(wr_qty_rjct,0))
              * opcost2) + (max(reject,0) * opcost).
      do with frame d:
         display
            wo_nbr
            wo_lot
            wo_status
            wr_op
            worouting
            reject
            wr_qty_wip
            opcost
            ext_wip WITH STREAM-IO /*GUI*/ .
         down 1.
      end.

      /********************** TOTALS OF WIP COST ******************************/

      accumulate ext_wip (total by in_site by pt_prod_line
                                by wo_part by wo_lot).

      if last-of (wo_lot) then do:
         if page-size - line-counter < 3 then
            page.
         underline ext_wip.
         down 1.

         display
            l_cum_order_total @ opcost
            accum total by wo_lot ext_wip @ ext_wip WITH STREAM-IO /*GUI*/ .
         down 2.
      end.

      if last-of (wo_part) then do:
         if page-size - line-counter < 4 then
            page.
         underline ext_wip.
         down 1.

         display
            l_item_total @ opcost
            accum total by wo_part ext_wip @ ext_wip WITH STREAM-IO /*GUI*/ .
         down 2.
      end.

      if last-of (pt_prod_line) then do:
         if page-size - line-counter < 4 then
            page.
         underline ext_wip.
         down 1.

         display
            l_product_line_total @ opcost
            accum total by pt_prod_line ext_wip @ ext_wip WITH STREAM-IO /*GUI*/ .
      end.

      if last-of (in_site) then do:
         if page-size - line-counter < 4 then
            page.
         underline ext_wip.
         down 1.

         display
            l_site_total @ opcost
            accum total by in_site ext_wip @ ext_wip WITH STREAM-IO /*GUI*/ .
      end.

      if last (in_site) then do:
         if page-size - line-counter < 2 then
            page.
         underline ext_wip.
         down 1.

         display
            l_report_total @ opcost
            accum total ext_wip @ ext_wip WITH STREAM-IO /*GUI*/ .
      end.

      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

   end. /* for each */

   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

end.  /* repeat */

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" site site1 part part1 ptgroup group1 line line1 vend vend1 abc abc1 wip_cost "} /*Drive the Report*/
